//
//  ZXSaleController.m
//  qianke
//
//  Created by ZX on 2017/7/17.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXSaleController.h"
#import "ZXSaleBeforeView.h"
#import "ZXSaleBeforeCell.h"
#import "ZXsaleModel.h"
@interface ZXSaleController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *titleBgView;
@property (weak, nonatomic) IBOutlet UIButton *leftTitleBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightTitleBtn;
@property (weak, nonatomic) IBOutlet UIView *btnBigView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (weak, nonatomic) IBOutlet UIView *emptyView;
@property (weak, nonatomic) IBOutlet UILabel *emptyLabel;

/*saleBeforeArr*/
@property(copy ,nonatomic)NSMutableArray*saleBeforeArr;
/*xiaoshouguwenArr*/
@property(copy ,nonatomic)NSMutableArray*xiaoshouguwenArr;
/*dianneixinxiArr*/
@property(copy ,nonatomic)NSMutableArray*dianneixinxiArr;
/*saleBeforeLeaderArr*/
@property(copy ,nonatomic)NSMutableArray*saleBeforeLeaderArr;
/*saleAfterArr*/
@property(copy ,nonatomic)NSMutableArray*saleAfterArr;
/*saleAfterLeaderArr*/
@property(copy ,nonatomic)NSMutableArray*saleAfterLeaderArr;
/*saleBeforeLeaderArr*/
@property(copy ,nonatomic)NSMutableArray*saleBeforeLeaderRightArr;
/*saleAfterArr*/
@property(copy ,nonatomic)NSMutableArray*saleAfterRightArr;
/*saleAfterLeaderArr*/
@property(copy ,nonatomic)NSMutableArray*saleAfterLeaderRightArr;

/*accountBalance*/
@property(copy ,nonatomic)NSString*accountBalance;
/*ownFunds*/
@property(copy ,nonatomic)NSString*ownFunds;
/*threePartyFunds*/
@property(copy ,nonatomic)NSString*threePartyFunds;
@end
static NSString * const saleBeforeCell = @"saleBeforeCell";
static NSString * const saleBeforeLeaderCell = @"saleBeforeLeaderCell";
static NSString * const saleafterCell = @"saleafterCell";
static NSString * const dianneixinxi = @"dianneixinxi";
static NSString * const xiaoshouguwen = @"xiaoshouguwen";
@implementation ZXSaleController
- (void)viewDidLoad {
    [super viewDidLoad];
    my_AppDelegate.isLandscape = YES;
    self.view.backgroundColor = baseBackgroundColor;
    _titleBgView.backgroundColor = baseBlueColor;
    [self layout];
    [self loadData];
    if(_headerViewType == 0){
        [self baobiao];
    }

}
#pragma mark --loadData
-(void)baobiao{
    NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getAccountInformation/%@",ZXBaseURL,my_AppDelegate.uid];
    NSURL *url = [NSURL URLWithString:string];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
    [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
    
    [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"%@",data);
            double liftRate = [[[data objectForKey:@"data"]objectForKey:@"accountBalance"] doubleValue]*1000;
            double accountBalance = round(liftRate);
            double liftRate2 = [[[data objectForKey:@"data"]objectForKey:@"ownFunds"] doubleValue]*1000;
            double ownFunds = round(liftRate2);
            double liftRate3 = [[[data objectForKey:@"data"]objectForKey:@"threePartyFunds"] doubleValue]*1000;
            double threePartyFunds = round(liftRate3);
            my_AppDelegate.accountBalance = [NSString stringWithFormat:@"%.2f元", accountBalance/1000];
            my_AppDelegate.ownFunds= [NSString stringWithFormat:@"%.2f元",ownFunds/1000];
            my_AppDelegate.threePartyFunds = [NSString stringWithFormat:@"%.2f元",threePartyFunds/1000];
        });
        
    } failure:^(NSError *error) {
        
    }];
}

-(void)loadData{
    NSLog(@"my_AppDelegate.isyididenglu==%d",my_AppDelegate.isyididenglu);
//    NSString * today = [ZXToolObj today];
    //NSLog(@"%@",today);
    NSString * todayBegin = [NSString stringWithFormat:@"%@",[ZXToolObj todayBegin]];
    NSString * todayEnd= [NSString stringWithFormat:@"%@",[ZXToolObj todayEnd]];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSDate* todayBegindate = [formatter dateFromString:todayBegin];
    NSDate* todayEnddate = [formatter dateFromString:todayEnd];
//    开始时间戳的值
    NSString *todayBegintimeSp = [NSString stringWithFormat:@"%ld", (long)[todayBegindate timeIntervalSince1970]];
//    结束时间戳的值d
    NSString *todayEndtimeSp = [NSString stringWithFormat:@"%ld", (long)[todayEnddate timeIntervalSince1970]];
    //NSLog(@"timeSp:%@\n%@",todayBegintimeSp,todayEndtimeSp); //时间戳的值
    [_listArr removeAllObjects];
    if (_headerViewType == 4) {
        //        销售顾问详情
        //  /  售前店长左上二级

         NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getSalesPerformanceDetail/%@?salesId=%@",ZXBaseURL,my_AppDelegate.uid,_adviserNo];
        string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSLog(@"%@",data);
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]) {
                [_xiaoshouguwenArr removeAllObjects];
                for (NSDictionary* dic in temArr) {
                    ZXxiaoshouguwen * model = [ZXxiaoshouguwen new];
                    if (dic&&![dic isEqual:[NSNull null]]){
                        [model setValuesForKeysWithDictionary:dic];
                    }
                    [_xiaoshouguwenArr addObject:model];
                }
                _listArr = [_xiaoshouguwenArr mutableCopy];
                //NSLog(@"%@",_listArr);
                    [_myTableView reloadData];

                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;_emptyLabel.hidden = NO;
                    _emptyLabel.hidden = NO;
                }
            });
        } failure:^(NSError *error) {
            
        }];

        
    } else if(_headerViewType == 0){
        //        售前销售
        //  /  售前店长左上
        NSString * string= [NSString stringWithFormat:@"%@scrmForApp/report/getSalesPerformance/%@",ZXBaseURL, my_AppDelegate.uid];
        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        _rightTitleBtn.enabled = NO;
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                //NSLog(@"%@",data);
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]){
                [_saleBeforeArr removeAllObjects];
                for (NSDictionary* dic in temArr) {
                    ZXSaleBeforeModel * model = [ZXSaleBeforeModel new];
                    if (dic&&![dic isEqual:[NSNull null]]){
                        [model setValuesForKeysWithDictionary:dic];
                    }

                    [_saleBeforeArr addObject:model];
                }
                _listArr = [_saleBeforeArr mutableCopy];
                //NSLog(@"%@",_listArr);
                    [_myTableView reloadData];

                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                }
                _rightTitleBtn.enabled = YES;
            });
        } failure:^(NSError *error) {
            _rightTitleBtn.enabled = YES;
        }];

    }else if(_headerViewType == 1){
        //        售前督导
//        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreSalesInformation/%@",ZXBaseURL,my_AppDelegate.uid];
        NSString * month = [NSString stringWithFormat:@"%@",[ZXToolObj getMonth]];
        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreSalesInformation/%@?year=2017&month=%@",ZXBaseURL,my_AppDelegate.uid,month];
        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        my_AppDelegate.resultName = @"售前督导";
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"%@",data);
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]){
                    
                    [_saleBeforeLeaderArr removeAllObjects];
                    for (NSDictionary* dic in temArr) {
                        ZXZXSaleBeforeLeaderModel * model = [ZXZXSaleBeforeLeaderModel new];
                        if (dic&&![dic isEqual:[NSNull null]]){
                            [model setValuesForKeysWithDictionary:dic];
                        }

                        [_saleBeforeLeaderArr addObject:model];
                    }
                    _listArr = [_saleBeforeLeaderArr mutableCopy];
                    //NSLog(@"%@",_listArr);
                    [_myTableView reloadData];

                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                }
            });
        } failure:^(NSError *error) {
            
        }];
       

    }else if(_headerViewType == 2){
        //        售后店长
        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreRevenue/%@?startTime=%@&endTime=%@",ZXBaseURL,my_AppDelegate.uid,todayBegintimeSp,todayEndtimeSp];
        //NSLog(@"url==%@",string);
        string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];

        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                //NSLog(@"%@",data);
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]){
                    [_saleAfterArr removeAllObjects];
                    for (NSDictionary* dic in temArr) {
                        ZXSaleAfterModel * model = [ZXSaleAfterModel new];
                        if (dic&&![dic isEqual:[NSNull null]]){
                            [model setValuesForKeysWithDictionary:dic];
                        }
                        [_saleAfterArr addObject:model];
                    }
                    _listArr = [_saleAfterArr mutableCopy];
                    //NSLog(@"%@",_listArr);
                    
                    [_myTableView reloadData];
                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                }
            });
        } failure:^(NSError *error) {
            //NSLog(@"error=%@",error);
        }];
        

    }else if(_headerViewType == 3){
        //        店内信息
        NSString * month = [NSString stringWithFormat:@"%@",[ZXToolObj getMonth]];
        //NSLog(@"%@",month);
//        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getVehicleliftPlanByuid/%@?year=2017&month=%@",ZXBaseURL,my_AppDelegate.uid,month];
        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getVehicleliftPlanByDealerId/%@?year=2017&month=%@",ZXBaseURL,my_AppDelegate.uid,month];
        
        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                //NSLog(@"%@",data);
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]){
                    
                    [_dianneixinxiArr removeAllObjects];
                    for (NSDictionary* dic in temArr) {
                        ZXdianneixinxi * model = [ZXdianneixinxi new];
                        if (dic&&![dic isEqual:[NSNull null]]){
                            [model setValuesForKeysWithDictionary:dic];
                        }

                        [_dianneixinxiArr addObject:model];
                    }
                    _listArr = [_dianneixinxiArr mutableCopy];
                    //NSLog(@"%@",_listArr);
                    [_myTableView reloadData];
                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                }
            });
        } failure:^(NSError *error) {
            
        }];
        

    } else if(_headerViewType == 5){
        //        售后督导
        NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreRevenue/%@?startTime=%@&endTime=%@",ZXBaseURL,my_AppDelegate.uid,todayBegintimeSp,todayEndtimeSp];
        string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *url = [NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
        
        [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
            dispatch_async(dispatch_get_main_queue(), ^{
                //NSLog(@"%@",data);
                if (my_AppDelegate.isyididenglu==2) {
                    [self.navigationController popViewControllerAnimated:YES];
                }
                NSArray * temArr = [data objectForKey:@"data"];
                if (temArr&&![temArr isEqual:[NSNull null]]){
                    [_saleAfterLeaderArr removeAllObjects];
                    for (NSDictionary* dic in temArr) {
                        ZXSaleAfterModel * model = [ZXSaleAfterModel new];
                        if (dic&&![dic isEqual:[NSNull null]]){
                            [model setValuesForKeysWithDictionary:dic];
                        }

                        [_saleAfterLeaderArr addObject:model];
                    }
                    _listArr = [_saleAfterLeaderArr mutableCopy];
                    //NSLog(@"%@",_listArr);
                    [_myTableView reloadData];

                    
                }else{
                    _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                }
            });
        } failure:^(NSError *error) {
            
        }];
        


    }
    [_myTableView reloadData];
}
#pragma mark --tableview


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_headerViewType == 0) {
//        售前店长
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:saleBeforeCell];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[0];
            }
        }
        //NSLog(@"%@",_listArr[indexPath.row]);
        cell.ZXSaleBeforeModel1 = _listArr[indexPath.row];
        return cell;
    } else if (_headerViewType == 1){
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:saleBeforeLeaderCell];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[1];
            }
        }
        cell.ZXZXSaleBeforeLeaderModel1 = _listArr[indexPath.row];

        return cell;
        //        售前督导
    }else if (_headerViewType == 2){
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:saleafterCell];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[2];
            }
        }
        cell.ZXSaleAfterModel1 = _listArr[indexPath.row];
        return cell;
        //        售后店长
    }else if (_headerViewType == 5){
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:saleafterCell];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[2];
            }
        }
        cell.ZXSaleAfterModel1 = _listArr[indexPath.row];

        return cell;
        //        售后督导
    }
    else if (_headerViewType == 3){
        //        店内账户信息
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:dianneixinxi];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[3];
            }
        }
        cell.ZXdianneixinxi1 = _listArr[indexPath.row];
        return cell;
    }else{
        ZXSaleBeforeCell * cell = [tableView dequeueReusableCellWithIdentifier:xiaoshouguwen];
        if (!cell) {
            if (cell == nil) {
                NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ZXSaleBeforeCell" owner:nil options:nil];
                cell = nibs[4];
            }
        }
        cell.ZXxiaoshouguwen1 = _listArr[indexPath.row];;
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (_headerViewType == 5) {
        ZXSaleBeforeView * view = [[NSBundle mainBundle] loadNibNamed:@"ZXSaleBeforeView" owner:self options:nil][2];
        return view;
    }else if (_headerViewType == 4){
        ZXSaleBeforeView * view = [[NSBundle mainBundle] loadNibNamed:@"ZXSaleBeforeView" owner:self options:nil][_headerViewType];
        view.ownFundsLabel.text = _ownFunds;
        return view;
    }else{
        ZXSaleBeforeView * view = [[NSBundle mainBundle] loadNibNamed:@"ZXSaleBeforeView" owner:self options:nil][_headerViewType];
        return view;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (_headerViewType == 3) {
        return 60;
    }else return 30;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ZXSaleBeforeCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.userInteractionEnabled = NO;
    if (_headerViewType == 0) {
        ZXSaleController * saleVc = [ZXSaleController new];
        saleVc.btnBigViewHidden = YES;
        saleVc.horizontalScreen = YES;
        saleVc.headerViewType = 4;
        saleVc.noticeId = cell.XNoticeId;
        saleVc.adviserNo = cell.adviserNo;
        saleVc.labelTitle = @"销售顾问详情";
        [self.navigationController pushViewController:saleVc animated:NO];
    }
    cell.userInteractionEnabled = YES;
}
#pragma mark -- subViews
-(void)layout{
    [_rightTitleBtn setBackgroundColor:baseBlueColor];
    [_rightTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_leftTitleBtn setTitle:_leftTitle forState:UIControlStateNormal];
    [_rightTitleBtn setTitle:_rightTitle forState:UIControlStateNormal];
    _titleLabel.text = _labelTitle;
    
    _btnBigView.layer.borderWidth = 1;
    _btnBigView.layer.borderColor = [UIColor whiteColor].CGColor;
    _btnBigView.layer.masksToBounds = YES;
    _btnBigView.layer.cornerRadius = 6;
    _btnBigView.hidden = _btnBigViewHidden;
    if (!_listArr) {
        _listArr = [[NSMutableArray alloc]init];
    }
    if (!_xiaoshouguwenArr) {
        _xiaoshouguwenArr = [[NSMutableArray alloc]init];
    }
    if (!_saleBeforeArr) {
        _saleBeforeArr = [[NSMutableArray alloc]init];
    }
    if (!_dianneixinxiArr) {
        _dianneixinxiArr = [[NSMutableArray alloc]init];
    }
    if (!_saleBeforeLeaderArr) {
        _saleBeforeLeaderArr = [[NSMutableArray alloc]init];
    }
    if (!_saleAfterArr) {
        _saleAfterArr = [[NSMutableArray alloc]init];
    }
    if (!_saleAfterLeaderArr) {
        _saleAfterLeaderArr = [[NSMutableArray alloc]init];
    }
    if (!_saleAfterRightArr) {
        _saleAfterRightArr = [[NSMutableArray alloc]init];
    }
    if (!_saleAfterLeaderRightArr) {
        _saleAfterLeaderRightArr = [[NSMutableArray alloc]init];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    self.navigationController.navigationBar.hidden = YES;
    
    NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
    [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
    
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    my_AppDelegate.isLandscape = YES;
    if (my_AppDelegate.isyididenglu == 2) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLogfun;
    my_AppDelegate.isLandscape = NO;
    
}


#pragma mark --screen StatusBar

//支持的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
    
}

//是否可以旋转
-(BOOL)shouldAutorotate
{
    return NO;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;
    
}


//设置样式
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

//设置是否隐藏
- (BOOL)prefersStatusBarHidden {
    return NO;
}

//设置隐藏动画
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationNone;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark buttonClick
- (IBAction)backClick:(id)sender {
    my_AppDelegate.isLandscape = NO;
    [self.navigationController popViewControllerAnimated:NO];
}
- (IBAction)leftBtnClick:(id)sender {
//    NSString * thisbeginTim = [ZXToolObj getMonthBeginWith:[NSString stringWithFormat:@"2017-%@",[ZXToolObj getMonth]]];
//    NSString * thisendTim = [ZXToolObj getMonthEndWith:[NSString stringWithFormat:@"2017-%@",[ZXToolObj getMonth]]];
    //NSLog(@"%@\n%@",thisbeginTim,thisendTim);
    _leftTitleBtn.backgroundColor = baseBlueColor;
    _rightTitleBtn.backgroundColor = [UIColor whiteColor];
    [_leftTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_rightTitleBtn setTitleColor:baseBlueColor forState:UIControlStateNormal];
    if (_headerViewType == 0) {
        _headerViewType = 3;
    }
    
    if (_headerViewType == 0){
        //        售前销售
        if (_saleBeforeArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleBeforeArr mutableCopy];
        }
        
    }else if(_headerViewType == 2){
        //        售后店长
        if (_saleAfterRightArr.count == 0) {
            NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreRevenue/%@",ZXBaseURL,my_AppDelegate.uid];
            string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

            NSURL *url = [NSURL URLWithString:string];
            
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
            [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
            [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
                dispatch_async(dispatch_get_main_queue(), ^{
//                    //NSLog(@"%@",data);
                    if (my_AppDelegate.isyididenglu==2) {
                        [self.navigationController popViewControllerAnimated:YES];
                    }
                    NSArray * temArr = [data objectForKey:@"data"];
                    if (temArr&&![temArr isEqual:[NSNull null]]){
                        [_saleAfterRightArr removeAllObjects];
                        for (NSDictionary* dic in temArr) {
                            ZXSaleAfterModel * model = [ZXSaleAfterModel new];
                            if (dic&&![dic isEqual:[NSNull null]]){
                                [model setValuesForKeysWithDictionary:dic];
                            }
                            [_saleAfterRightArr addObject:model];
                        }
                        _listArr = [_saleAfterRightArr mutableCopy];
//                        //NSLog(@"%@",_listArr);
                        [_myTableView reloadData];
                    }else{
                        _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                    }
                });
            } failure:^(NSError *error) {
                //NSLog(@"%@",error);
            }];

        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleAfterRightArr mutableCopy];
        }
        
    }else if(_headerViewType == 3){
        //        店内信息
        if (_dianneixinxiArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_dianneixinxiArr mutableCopy];
            [_myTableView reloadData];
        }
        
    } else if(_headerViewType == 5){
        //        售后督导
        if (_saleAfterLeaderRightArr.count == 0) {
            NSString * string = [NSString stringWithFormat:@"%@scrmForApp/report/getStoreRevenue/%@",ZXBaseURL,my_AppDelegate.uid];
            string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

            NSURL *url = [NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
            [request addValue:my_AppDelegate.access_token forHTTPHeaderField:accessTokenKey];
            [HTTPHelper GetHeadmutableRequest:request success:^(NSDictionary *data) {
                dispatch_async(dispatch_get_main_queue(), ^{
//                    //NSLog(@"%@",data);
                    if (my_AppDelegate.isyididenglu==2) {
                        [self.navigationController popViewControllerAnimated:YES];
                    }
                    NSArray * temArr = [data objectForKey:@"data"];
//                    //NSLog(@"temArr=%@",temArr);
                    [_saleAfterLeaderRightArr removeAllObjects];
                    if (temArr&&![temArr isEqual:[NSNull null]]){
                        for (NSDictionary* dic in temArr) {
                            ZXSaleAfterModel * model = [ZXSaleAfterModel new];
                            if (dic&&![dic isEqual:[NSNull null]]){
                                [model setValuesForKeysWithDictionary:dic];
                            }
                            [_saleAfterLeaderRightArr addObject:model];
                            //NSLog(@"model = %@",model);
                        }
                        _listArr = [_saleAfterLeaderRightArr mutableCopy];
                        //NSLog(@"%@",_listArr);
                        
                        [_myTableView reloadData];
                    }else{
                        _emptyView.hidden = NO;_emptyLabel.hidden = NO;
                    }
                });
            } failure:^(NSError *error) {
                
            }];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleAfterLeaderRightArr mutableCopy];
            [_myTableView reloadData];
        }
    }
    [_myTableView reloadData];

    //NSLog(@"点击右边");
}
- (IBAction)rightBtnClick:(id)sender {
    _rightTitleBtn.enabled = NO;
    _emptyLabel.hidden = YES;
    _emptyView.hidden = YES;
    _rightTitleBtn.backgroundColor = baseBlueColor;
    _leftTitleBtn.backgroundColor = [UIColor whiteColor];
    [_rightTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_leftTitleBtn setTitleColor:baseBlueColor forState:UIControlStateNormal];
    if (_headerViewType == 3) {
        _headerViewType = 0;
    }
    if (_headerViewType == 0){
        //        售前销售
        if (_saleBeforeArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleBeforeArr mutableCopy];
        }

    }else if(_headerViewType == 2){
        //        售后店长
        if (_saleAfterArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleAfterArr mutableCopy];
        }
        
    }else if(_headerViewType == 3){
        //        店内信息
        if (_dianneixinxiArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_dianneixinxiArr mutableCopy];
        }
        
    } else if(_headerViewType == 5||_headerViewType == 5){
        //        售后督导
        if (_saleAfterLeaderArr.count == 0) {
            [self loadData];
        }else{
            [_listArr removeAllObjects];
            _listArr = [_saleAfterLeaderArr mutableCopy];
        }
    }
    _rightTitleBtn.enabled = YES;
    [_myTableView reloadData];
    //NSLog(@"点击左边");
    
    }

@end
